package test;
import java.util.Scanner;
import static java.lang.Math.max;
public class test2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 输入数组长度
        int n = scanner.nextInt();
        int[] nums = new int[n];
        // 输入数组元素
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }

        // 处理数组长度为0的情况
        if (n == 0) {
            System.out.println(0);
            scanner.close();
            return;
        }

        int mx = nums[0];
        int s = nums[0];
        for (int i = 1; i < n; i++) {
            s = max(s + nums[i], nums[i]);
            mx = max(mx, s);
        }
        System.out.println(mx);
        scanner.close();
    }
}